package com.yang.simple_rpc.common.protocol;

/**
 * 消息协议，定义消息编组请求，解组请求，编组响应，解组响应的规范
 *
 * @author : morikawaaaa
 * @date : 2022
 */
public interface MessageProtocol {

    /**
     * client编组请求
     * @param req 请求消息
     * @return 字节数组
     * @throws Exception 编组请求异常
     */
    byte[] marshallingRequest(SimpleRequest req) throws Exception;


    /**
     * server解组请求
     * @param bytes client传输过来的字节流
     * @return client的请求消息
     * @throws Exception
     *
     */
    SimpleRequest unmarshallingRequest(byte[] bytes) throws Exception;

    byte[] marshallingResponse(SimpleResponse resp) throws Exception;
    SimpleResponse unmarshallingReponse(byte[] bytes) throws Exception;
}
